import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/routers/router_init.dart';
import 'package:ls_work/routers/404.dart';
import 'package:ls_work/init_page/webview_page.dart';
import 'package:ls_work/a_yyt/home_router.dart';
import 'package:ls_work/a_message/mall_router.dart';
import 'package:ls_work/a_elder/elder_router.dart';
import 'package:ls_work/a_mine/my_router.dart';
import 'package:ls_work/login/login_router.dart';

import 'package:ls_work/init_page/init_page.dart';

class Routes {
  static String inithome = "/initHome";
  static String webViewPage = "/webview";

  static List<IRouterProvider> _listRouter = [];

  static void configureRoutes(FluroRouter router) {
    /// 指定路由跳转错误返回页
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      debugPrint("未找到目标页");
      return WidgetNotFound();
    });

    router.define(inithome,
        handler: Handler(
            handlerFunc:
                (BuildContext? context, Map<String, List<String>> params) =>
                    InitPage()));

    router.define(webViewPage, handler: Handler(handlerFunc: (_, params) {
      String title = params['title']?.first??"";
      String url = params['url']?.first??"";
      return WebViewPage(title: title, url: url);
    }));

    _listRouter.clear();

    /// 各自路由由各自模块管理，统一在此添加初始化
    _listRouter.add(HomeRouter());
    _listRouter.add(MallRouter());
    _listRouter.add(ElderRouter());
    _listRouter.add(MyRouter());
    _listRouter.add(LoginRouter());

    /// 初始化路由
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}
